<template>
  <div class="app-container">
    <!-- <template>
      <el-tag>
        <span>CMK总量: CMK {{ totalCmkAmt }}</span>
      </el-tag>
      <el-tag>
        <span>今日释放: CMK {{ releaseCmkAmt }}</span>
      </el-tag>
      <el-tag>
        <span>待释放: CMK {{ surplusCmkAmt }}</span>
      </el-tag>
      <el-tag>
        <span>交易价格: RMB {{ cmkAmtPrice }}</span>
      </el-tag>
      <el-tag>
        <span>交易额度: CMK {{ cmkAmtLimit }}</span>
      </el-tag>
    </template> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-edit" size="mini" @click="handleEdit"
          v-hasPermi="['admin:cmkManage:cmkAmtInfo:edit']">修改
        </el-button>
      </el-col>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="cmkAmtInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="PNC总量" align="center" prop="amtPrice" />
      <el-table-column label="今日释放" align="center" prop="releaseCmkAmt" />
      <el-table-column label="待释放" align="center" prop="surplusCmkAmt" /> -->
      <el-table-column label="交易价格" align="center" prop="amtPrice" />
      <!-- <el-table-column label="交易额度" align="center" prop="cmkAmtLimit" /> -->
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="最后更新时间" align="center" prop="lastModifiedTime" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 修改 -->
    <el-dialog :title="title" :visible.sync="open" width="400px" append-to-body @close="cancel">
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
        <el-form-item label="交易PNC价格" prop="amtPrice">
          <el-input v-model="form.amtPrice" placeholder="请输入交易价格" />
        </el-form-item>
        <!-- <el-form-item label="交易额度" prop="cmkAmtLimit">
          <el-input v-model="form.cmkAmtLimit" placeholder="请输入交易额度" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getCmkAmtInfoList, getLastCmkAmtInfo, updateInfo } from "@/api/admin/feedback";

export default {
  name: "Goods",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 创呗交易记录表格数据
      cmkAmtInfoList: [],
      totalCmkAmt: 0,
      releaseCmkAmt: 0,
      surplusCmkAmt: 0,
      cmkAmtPrice: 0,
      cmkAmtLimit: 0,
      form: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      //表单校验
      rules: {
        amtPrice: [{ required: true, message: "请输入交易价格", trigger: "blur" }],
        // cmkAmtLimit: [{ required: true, message: "请输入交易额度", trigger: "blur" }]
      },
    };
  },

  created() {
    this.getLastCmkAmtInfo();
    this.getList();
  },

  methods: {
    /** 查询商品分类列表 */
    getList() {
      this.loading = true;
      getCmkAmtInfoList(this.queryParams).then((response) => {
        this.cmkAmtInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getLastCmkAmtInfo() {
      getLastCmkAmtInfo().then((response) => {
        this.totalCmkAmt = response.data.totalCmkAmt;
        this.releaseCmkAmt = response.data.releaseCmkAmt;
        this.surplusCmkAmt = response.data.surplusCmkAmt;
        this.cmkAmtPrice = response.data.cmkAmtPrice;
        this.cmkAmtLimit = response.data.cmkAmtLimit;
      });
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },

    handleEdit() {
      this.open = true;
      let that = this;
      getLastCmkAmtInfo().then((response) => {
        that.form = { id: response.data.id, amtPrice: response.data.amtPrice };
      });
    },

    // 取消按钮
    cancel() {
      this.reset();
      this.open = false;
    },

    //提交按钮
    submitForm() {
      updateInfo(this.form).then((response) => {
        if (response.code === 200) {
          this.msgSuccess("修改成功!");
          this.cancel();
          this.getList();
          this.getLastCmkAmtInfo();
        }
      });
    },
  },
};
</script>
<style scoped>
.el-tag {
  padding: 58px;
  font-size: 20px;
}
</style>